###################
# Calculating variable
###################

# All the internal Projects that the current Project depends on
prj_depends:=$(prj_int_static_libs) $(prj_int_shared_libs) $(prj_int_just_copy) $(prj_int_pgms)
prj_depends:=$(strip $(prj_depends))

# All the internal Projects that the test of the current Project depends on
test_depends:=$(test_int_static_libs) $(test_int_shared_libs) $(test_int_just_copy) $(test_int_pgms)
test_depends:=$(strip $(test_depends))

# -D options used to compile the Project
final_prj_minus_d:=-DPRJ=\"$(project)\" $(site_prj_minus_d) $(site_minus_d) $(prj_minus_d)
final_prj_minus_d:=$(strip $(final_prj_minus_d))


# -D options passed to compile the Test of the Project
final_test_minus_d:=-DPRJ=\"$(project)\" $(site_test_minus_d) $(site_minus_d) $(test_minus_d)
final_test_minus_d:=$(strip $(final_test_minus_d))

##### Paths

# all the include directories for the Project
final_prj_inc_dir:=$(build_inc_dir) $(site_prj_ext_inc_dir) $(prj_ext_inc_dir) $(dir_incs)
final_prj_inc_dir:=$(strip $(final_prj_inc_dir))
final_prj_inc_dir:=$(final_prj_inc_dir:%=$(inc_dir_flag)%)

# all the include directories for the Test
final_test_inc_dir:=$(site_test_ext_inc_dir) $(test_ext_inc_dir) $(dir_inc) $(dir_tst)
final_test_inc_dir:=$(final_test_inc_dir:%=$(inc_dir_flag)%)
final_test_inc_dir:=$(final_prj_inc_dir) $(final_test_inc_dir) 
final_test_inc_dir:=$(strip $(final_test_inc_dir))

# all the shared library directories for the Project
final_prj_lib_dir:=$(dir_lib) $(site_prj_ext_lib_dir)
final_prj_lib_dir:=$(final_prj_lib_dir:%=$(lib_dir_flag) %)
final_prj_lib_dir:=$(strip $(final_prj_lib_dir))

# all the shared library directories for the Test
final_test_lib_dir:=$(site_test_ext_lib_dir) $(test_ext_lib_dir)
final_test_lib_dir:=$(final_prj_lib_dir) $(final_test_lib_dir:%=$(lib_dir_flag) %)
final_test_lib_dir:=$(strip $(final_test_lib_dir))

##### Shared Libraries

# all the shared libraries referenced by the Project
final_prj_shared_libs:=$(site_prj_ext_shared_libs) $(prj_ext_shared_libs) $(prj_int_shared_libs)
final_prj_shared_libs:=$(final_prj_shared_libs:%=$(shared_lib_flag)%)
final_prj_shared_libs:=$(strip $(final_prj_shared_libs))

# all the shared libraries referenced by the Test
final_test_shared_libs:=$(site_test_ext_shared_libs) $(test_ext_shared_libs) $(test_int_shared_libs)
final_test_shared_libs:=$(final_test_shared_libs:%=$(shared_lib_flag)%)
final_test_shared_libs:=$(final_prj_shared_libs) $(final_test_shared_libs)
final_test_shared_libs:=$(strip $(final_test_shared_libs))

##### Static Libraries

# all the static libraries referenced by the Project
final_prj_static_libs:=$(site_prj_ext_static_libs) $(prj_ext_static_libs) $(prj_int_static_libs:%=$(build_lib_dir)/$(static_prefix)%$(static_sufix))
final_prj_static_libs:=$(strip $(final_prj_static_libs))

# all the static libraries referenced by the Test
final_test_static_libs:=$(site_test_ext_static_libs) $(test_ext_static_libs) $(test_int_static_libs:%=$(build_lib_dir)/$(static_prefix)%$(static_sufix))
final_test_static_libs:=$(final_prj_static_libs) $(final_test_static_libs)
final_test_static_libs:=$(strip $(final_test_static_libs))

##### Programs

# all the programs referenced by the Project
final_prj_pgms:=$(prj_int_pgms:%=$(program_prefix)%$(program_sufix)) $(site_prj_ext_pgms) $(prj_ext_pgms)
final_prj_pgms:=$(strip $(final_prj_pgms))

# all the programs referenced by the Test
final_test_pgms:=$(test_int_pgms:%=$(program_prefix)%$(program_sufix)) $(site_test_ext_pgms) $(test_ext_pgms)
final_test_pgms:=$(final_prj_pgms) $(final_test_pgms)
final_test_pgms:=$(strip $(final_test_pgms))

##### Just-copy

# all the just-copy referenced by the Project
final_prj_just_copy:=$(prj_int_just_copy)
final_prj_just_copy:=$(strip $(final_prj_just_copy))

##### Qt files to C++ files

# automatic list of qt user interface code files
#qt_code:=$(shell ls $(dir_src)/*.$(qt_extension) 2> /dev/null)
#qt_code:=$(strip $(qt_code))

# automatic list of Project source files based on the Qt header files
#qt_code_cpps:=$(subst .$(qt_extension),.$(source_extension),$(qt_code))
#qt_code_cpps:=$(strip $(qt_code_cpps))


# automatic list of Project header files based on the Qt header files
#qt_code_hs:=$(subst .$(qt_extension),.$(header_extension),$(qt_code))
#qt_code_hs:=$(strip $(qt_code_hs))

# automatic list of qt user interface test files
#qt_test:=$(shell ls $(dir_code)/test/*.$(qt_extension) 2> /dev/null)
#qt_test:=$(strip $(qt_test))

# automatic list of Test header files based on the Qt header files
#qt_test_hs:=$(subst .$(qt_extension),.$(header_extension), $(qt_test))
#qt_test_hs:=$(strio $(qt_test_hs))

# automatic list of Test header source based on the Qt header files
#qt_test_cpps:=$(subst .$(qt_extension),.$(source_extension), $(qt_test))
#qt_test_cpps:=$(strip $(qt_test_cpps))


##### Source and Object list

# automatic list of C++ source files for the Code
cpp_code_srcs:=$(wildcard $(dir_src)/*.$(source_extension)) 
#$(qt_code_cpps)
cpp_code_srcs:=$(strip $(cpp_code_srcs)) 

# automatic list of C++ object files for the Code
tmp_cpp_code_objs:=$(cpp_code_srcs:.$(source_extension)=.o)
cpp_code_objs:=$(subst src/$(project)/,obj/$(project)/,$(tmp_cpp_code_objs))
cpp_code_objs:=$(strip $(cpp_code_objs))

# automatic list of C source files for the Code
c_code_srcs:=$(wildcard $(dir_src)/*.c)
c_code_srcs:=$(strip $(c_code_srcs))

# automatic list of C object files for the Code
tmp_c_code_objs:=$(c_code_srcs:.c=.o)
c_code_objs:=$(subst src/$(project)/,obj/$(project)/,$(tmp_c_code_objs))
c_code_objs:=$(strip $(c_code_objs))

# automatic list of all the source files for the Code
code_srcs:=$(cpp_code_srcs)
code_srcs:=$(strip $(code_srcs))
#$(c_code_srcs)

# automatic list of all the object files for the Code
code_objs:=$(cpp_code_objs)
code_objs:=$(strip $(code_objs))
#$(c_code_objs)

# automatic list of source files for the Test
test_srcs:=$(wildcard $(dir_tst)/*.$(source_extension)) $(qt_test_cpps)
test_srcs:=$(strip $(test_srcs)) 
#$(code_srcs)

# atomatic list of object files for the Test
t_objs_test:=$(test_srcs:.$(source_extension)=.o)
#test_objs:=$(subst $(dir_tst)src/$(project)/test/,bin/$(project)/test/$(coc)/,$(t_objs_test)) $(code_objs)
#test_objs:=$(strip $(test_objs))
test_objs:=$(strip $(t_objs_test)) $(code_objs)




# **************  creates the necessary directories for a project
# this is not a 'public' command, therefore, it must not be used directly
setup :
	$(show) ""                                                           ; \
	mkdir -p $(dir_prj)                                     2> /dev/null ; \
	mkdir -p $(dir_bin)                                     2> /dev/null ; \
	mkdir -p $(dir_lib)                                     2> /dev/null ; \
	mkdir -p $(dir_src)                                     2> /dev/null ; \
	mkdir -p $(dir_obj)                                     2> /dev/null ; \
	mkdir -p $(dir_inc)                                     2> /dev/null ; \
	mkdir -p $(dir_inp)                                     2> /dev/null ; \
	mkdir -p $(dir_out)                                     2> /dev/null ; \
	mkdir -p $(dir_doc)                                     2> /dev/null ; \
	mkdir -p $(dir_cfg)/translation                         2> /dev/null ; \
	mkdir -p $(dir_tst)                                    2> /dev/null ; \
	if [ ! -f "$(dir_prj)/project.mk" ]; then                              \
		cp -f "$(dir_tool)/aux_files/project.mk"                       \
			"$(dir_prj)/project.mk"                 2> /dev/null ; \
	fi                                                                   ; \

# **************  executes a target for all the references
chain :
	$(show) ""                                                           ; \
	refs=`echo "$(prj_depends)" | tr -s " "`                             ; \
	refs=`echo "$$refs" | tr [:space:] "-"`                              ; \
	if [ ! -z $$refs ]; then                                               \
		cont_ref=1                                                   ; \
		ref=`echo $$refs | cut -d '-' -f$$cont_ref`                  ; \
		while [ ! -z "$$ref" ]; do                                     \
			make project="$$ref" coc=$(coc)        \
				verbose=$(verbose) target=$(target)            \
				chain_target=$(chain_target)                   \
				M_version=$(M_version) m_version=$(m_version)  \
				build_number=$(build_number)  chain          ; \
			make project="$$ref" coc=$(coc)        \
				verbose=$(verbose) target=$(target)            \
				M_version=$(M_version) m_version=$(m_version)  \
				build_number=$(build_number) $(chain_target) ; \
			cont_ref=`echo $$cont_ref+1 | bc`                    ; \
			ref1=`echo $$refs | cut -d '-' -f$$cont_ref`         ; \
			if [ "$$ref" = "$$ref1" -a $$cont_ref -eq 2 ] ; then   \
				ref=""                                       ; \
			else                                                   \
				ref=$$ref1                                   ; \
			fi                                                   ; \
		done                                                         ; \
	fi                                                                   ;


# **************  creates the targets due to header files dependencies

dependencies:
	$(show) "no dependencies calculated"




